<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('特殊人员薪资登记')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: container-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="modal inmodal fade" id="myModal1" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h4 class="modal-title">选择薪资套类型</h4>
            </div>
            <div class="modal-body">
                <p>
                    <select id="pgid" name='pgid' class="form-control">
                    </select>
                </p>
            </div>
            <div class="modal-footer">
                <button type="button" id="missmodal1" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" onclick="getpgid()" class="btn btn-primary">确认</button>
            </div>
        </div>
    </div>
</div>
<button type="button" id="modal1" class="btn btn-primary" data-toggle="modal"
        data-target="#myModal1">选择薪资套
</button>


<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                工号：<input type="text" name="badge"/>
                            </li>
                            <li>
                                姓名：<input type="text" name="name"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="sealUp()">
                    <i class="fa fa-plus"></i> 封存
                </a>

            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>

<script th:inline="javascript">
    var prefix = ctx + "specialPersonSalaryRegister";
    var pgid;
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 800) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 350});
        $("#modal1").attr("style", "display:none;");
        getSkypayGroups();
        //queryData();
    });


    function getpgid() {
        pgid = $("#pgid").val();
        $("#missmodal1").click();
        if (pgid != undefined) {
            queryData();
        }
    }


    function sealUp() {
        if (pgid == undefined) {
            $.modal.alertWarning("尚未选择薪资套！");
        } else {
            //调用存储过程
            $.ajax({
                async: false,
                url: prefix + "/sealUp",
                data: {
                    "pgid": pgid
                },
                type: "post",
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        $.modal.alertWarning("操作成功！");
                        $("#bootstrap-table").bootstrapTable("refresh");
                        $(".layui-layer-btn0").click(function () {
                            if (z == 1) {
                                $(".btn-warning", parent.document).click();
                                $.modal.close();
                            }
                        });
                    } else if (data.code == 500) {
                        $.modal.alertWarning("服务器繁忙！");
                        $("#bootstrap-table").bootstrapTable("refresh");
                    } else {
                        $.modal.alertWarning(data.message);
                        $("#bootstrap-table").bootstrapTable("refresh");
                    }

                },
            });
        }
    }

    //获取数据集合
    function queryData() {
        var columns = [];
        var time = {field: 'term', title: '发薪时间', sortable: true};
        var badge = {field: 'badge', title: '工号', sortable: true};
        var name = {field: 'name', title: '姓名', sortable: true};
        var compName = {field: 'compName', title: '公司', sortable: true};
        var depName = {field: 'depName', title: '部门', sortable: true};
        var jobName = {field: 'jobName', title: '岗位', sortable: true};
        columns.push(time, badge, name, compName, depName, jobName);
        var other;
        $.ajax({
            async: false,
            url: ctx + "salaryCalculation/getPro",
            data: {"pgid": pgid},
            type: "post",
            dataType: "json",
            success: function (data) {
                for (var i = 0; i < data.length; i++) {
                    other = {
                        field: data[i], title: data[i], sortable: true
                    }
                    columns.push(other);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });

        var options = {
            url: prefix + "/list?pgid=" + pgid,
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove/{id}",
            exportUrl: prefix + "/export?pgid=" + pgid,
            escape: true,
            showPageGo: true,
            rememberSelected: true,
            pagination: false,
            showColumns: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            modalName: "基本信息",
            height: $(window).height() - 120,
            onLoadSuccess: function () {
                $(".th-inner").click(function () {
                    $(".fixed-table-loading").show();
                    setTimeout(function () {
                        $(".fixed-table-loading").hide();
                    }, 1000);
                });
            },
            columns: columns
        };
        $.table.init(options);
    }


    /**
     * 获取薪资套列表
     */
    function getSkypayGroups() {
        var html = "";
        $.ajax({
            async: false,
            url: ctx + "salaryCalculation/getSkypayGroups",
            data: {},
            type: "post",
            dataType: "json",
            success: function (data) {
                $("#pgid").empty();
                var arry = data;
                for (var i = 0; i < arry.length; i++) {
                    html += "<option value='"
                        + arry[i].id
                        + "'>"
                        + arry[i].title
                        + "</option>";
                }
                $("#pgid").append(html);
                $("#modal1").click();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

                alert("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

</script>
</body>
</html>